package com.ruiaa.meeting.service.impl;

import com.ruiaa.meeting.model.Api;
import com.ruiaa.meeting.model.ApiRelation;
import com.ruiaa.meeting.persistence.ApiMapper;
import com.ruiaa.meeting.persistence.ApiRelationMapper;
import com.ruiaa.meeting.service.ApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenhuaiyi
 * @date 2022-11-04 10:32
 */
@Service
public class ApiServiceImpl implements ApiService {

    @Autowired
    private ApiMapper apiMapper;
    @Autowired
    private ApiRelationMapper apiRelationMapper;

    @Override
    public List<Api> getRelationalApis(Integer thisId) {
        ApiRelation apiRelation = apiRelationMapper.selectById(thisId);
        String nextId = apiRelation.getNextId();
        String[] indexs = nextId.split(",");
        ArrayList<Api> apis = new ArrayList<>();
        for(String index : indexs){
            Api api = apiMapper.selectById(Integer.parseInt(index));
            apis.add(api);
        }
        return apis;
    }
}
